package startupcompanymanager2012;

import java.io.Serializable;

public class Developer implements Serializable {

    //Developers name
    private String name;
    //Different integer values for attributes and statistics
    private int speed, acurracy, bugsPerLine,
            experiencePoints, spent_attributes, level, gamesDeveloped = 0, daysWorked = 0,
            statsBudget = 33;
    //devs salary
    private double monthlySalary;
    //Attributes initial value and so on
    private static final int INITIAL_VALUE = 33, MAX_LINES_PER_DAY = 2000,
            EXPERIENCE_POINTS_PER_DAY = 2;
    public static final double BUGS_PER_LINE = 0.005, STAT_PER_EXPERIENCE_POINT = 0.1, BASE_SALARY = 600.00;
    //boolean if dev is working on project or not
    private boolean working;

    public Developer() {
        /*Creates a new Developer, generates a name, 
         * distributes the first statpoints randomly
         */
        this.name = Name.generate();
        this.experiencePoints = 0;
        this.level = 1;
        working = false;
        /**TODO Random generated attributes
         * Fix Algorithm! max 66% of the whole per stat, even chance for each one
         * Remind other Constructor!
         */
        distributeStats();
    }

    public Developer(String firstname, String lastname) {
        /*Constructor mainly for the main developer, 
         * since name is not generated
         */
        this.name = firstname + " " + lastname;
        this.experiencePoints = 0;
        this.level = 1;
        /**TODO Same as other Constructor!
         * Remind changing both!
         */
        distributeStats();
    }

    private void distributeStats() {
        //distributes the first statpoints randomly
        double rnd;

        rnd = Math.random();
        this.acurracy = INITIAL_VALUE + (int) (statsBudget * rnd);
        statsBudget = statsBudget - (int) (statsBudget * rnd);

        rnd = Math.random();
        this.speed = INITIAL_VALUE + (int) (statsBudget * rnd);
        statsBudget = statsBudget - (int) (statsBudget * rnd);

        this.bugsPerLine = INITIAL_VALUE + statsBudget;
        statsBudget = statsBudget - statsBudget;

        this.spent_attributes = 0;

    }

    public boolean upgrade() {
        /*TODO Create upgrade Method; Rewrite for GUI, integrate output in GUI!!!
         *Add remembering variable for spent points & correspronding Mechanic
         */
        int budget = (int) (this.getExperiencePoints() * STAT_PER_EXPERIENCE_POINT);
        int acurracy, quality, speed;
        do {
            System.out.println("Your Current Attribute weight is: ");
            System.out.println("Acurracy: \t" + this.acurracy);
            System.out.println("Code-Quality: \t" + this.bugsPerLine);
            System.out.println("Speed: \t" + this.speed);
            System.out.println("Your Attributes budget is: " + budget + ".");
            System.out.println("How much do you want to spend on");
            System.out.print("Acurracy: ");
            acurracy = Test.readInt();
            System.out.print("Code-Quality: ");
            quality = Test.readInt();
            System.out.print("Speed: ");
            speed = Test.readInt();
            System.out.println("Budget\tAcurracyt\tQuality\tSpeed");
            System.out.println(budget + "\t" + acurracy + "\t" + quality + "\t" + speed);
            if (acurracy < 0 || speed < 0 || quality < 0 || acurracy + quality + speed > budget) {
                System.out.println("\n Action not possible, please Retry!(enter 0 everywhere to exit)\n");
            }
        } while (acurracy < 0 || speed < 0 || quality < 0 || acurracy + quality + speed > budget);
        this.acurracy += acurracy;
        this.bugsPerLine += quality;
        this.speed += speed;
        this.spent_attributes = this.spent_attributes + (acurracy + quality + speed);
        return (acurracy + quality + speed <= budget && acurracy > 0 || speed > 0 || quality > 0);
    }
    //calculates the salary

    public double calculateSalary() {
        /*TODO REVIEW FORMULA*/
        double salary = BASE_SALARY * (1.00 + (gamesDeveloped / 100.00));
        return salary;
    }
    //subtracts the salary from the capital

    public double paySalary() {
        Test.capital -= this.monthlySalary;
        return this.monthlySalary;
    }

    @Override
    public String toString() {
        return name;
    }

    //different setters and getters
    public void setWorking(boolean working) {
        this.working = working;
    }

    public void setDaysWorked(int daysWorked) {
        this.daysWorked += daysWorked;
    }

    public void setExperiencePoints(int experiencePoints) {
        this.experiencePoints += experiencePoints;
    }

    public void setGamesDeveloped(int gamesDeveloped) {
        this.gamesDeveloped += gamesDeveloped;
    }

    public boolean getWorking() {
        return working;
    }

    public int getBugsPerLine() {
        return bugsPerLine;
    }

    public int getExperiencePoints() {
        return experiencePoints;
    }

    public String getName() {
        return name;
    }

    public int getSpeed() {
        return speed;
    }

    public int getLevel() {
        return level;

    }

    public static int getMAX_LINES_PER_DAY() {
        return MAX_LINES_PER_DAY;
    }

    public int getDaysWorked() {
        return daysWorked;
    }

    public int getGamesDeveloped() {
        return gamesDeveloped;
    }

    public double getMonthlySalary() {
        return monthlySalary;
    }

    public int getAcurracy() {
        return acurracy;
    }
}